package com.accesshollywood.grfxOrdering.panels;

import java.awt.Color;
import java.awt.Component;

import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.border.EtchedBorder;
import javax.swing.border.LineBorder;

import org.jdesktop.swingx.HorizontalLayout;
import org.jdesktop.swingx.VerticalLayout;

import com.accesshollywood.components.FoldablePanel;
import com.accesshollywood.grfxOrdering.ViewFilterCheckBox;
import com.accesshollywood.grfxOrdering.basics.Colors;

public class ViewFilterGroupPanel extends FoldablePanel {
	JPanel	groupNameSubPanel	= new JPanel();
	JPanel	filterSubPanel		= new JPanel();

	int		numChecked			= 0;

	public ViewFilterGroupPanel(String groupName) {
		super();

		groupNameSubPanel.setLayout(new HorizontalLayout());
		groupNameSubPanel.add(new JLabel(groupName));
		groupNameSubPanel.setBorder(new EtchedBorder(1));

		// filterSubPanel.setLayout(new
		// BoxLayout(filterSubPanel,BoxLayout.Y_AXIS));
		filterSubPanel.setLayout(new VerticalLayout());
		filterSubPanel.setBorder(new EtchedBorder(1));

		setBorder(new LineBorder(Color.BLACK, 2));
		setBackgroundIfAnyChecked();
	}

	public void makeFoldable(FoldablePanel.FOLD_STATE foldState) {
		this.setHeaderAndFoldUp(groupNameSubPanel, filterSubPanel, foldState);
	}

	public void setBackgroundIfAnyChecked() {
		groupNameSubPanel.setBackground(Color.WHITE);
		Component[] component = this.filterSubPanel.getComponents();
		for (int i = 0; i < component.length; i++) {
			if (component[i] instanceof ViewFilterCheckBox) {
				ViewFilterCheckBox currCheck = (ViewFilterCheckBox) component[i];
				if (currCheck.isSelected()) {

					groupNameSubPanel.setBackground(Colors.getColor(Colors.READY));
					return;
				}
			}
		}
		/*
		 * if(numChecked > 0){
		 * groupNameSubPanel.setBackground(Colors.getColor(Colors.READY));
		 * }else{
		 * groupNameSubPanel.setBackground(Color.WHITE);
		 * }
		 */
	}
}
